package DP.composite;

/**
 * @author msi
 * 场景类
 */
public class Client {
    public static void main(String[] args) {
        Composite composite=new Composite();
        composite.doSomething();
        Composite composite1=new Composite();
        Leaf leaf=new Leaf();
        composite.add(composite1);
        composite1.add(leaf);
    }

    //通过递归遍历树
    public static void display(Composite composite){
        for(Component component: composite.getChildren()){
            if(component instanceof Leaf){
                component.doSomething();
            }else{
                display((Composite) component);
            }
        }
    }
}
